<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>投票详情</title>

    <!--判断是否登陆-->
    <script type="text/javascript" src="../../vendor/jquery-2.0.3.min.js"></script>
    <script type="text/javascript" src="../../js/config.js"></script>
    <script type="text/javascript" src="../../js/jquerySession.js"></script>
    <script type="text/javascript">
        if ($.session.get('token') == null) {
            alert("用户未登录！");
            window.location.href = "../../login.html"
        }
    </script>

    <script src="../../vendor/echarts.common.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="main" style="height:450px;margin: 0px auto"></div>
<!-- ECharts单文件引入 -->
<script type="text/javascript">
    // 路径配置
    // 基于准备好的dom，初始化echarts图表

    //获取url地址传递过来的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    var id = getUrlParam("id");

    var myChart = echarts.init(document.getElementById('main'));
    var items = [];
    var numberOfVoter = [];
    $.getJSON(baseUrl + "/votes/" + id + "/records", function (json) {
        if (json.meta.code == "200") {
            $.each(json.data, function (i, data) {
                items.push(data.item);
                numberOfVoter.push(data.number)
            });
            var option = {
                tooltip: {
                    show: true
                },
                legend: {
                    data: ['得票数']
                },
                xAxis: [
                    {
                        type: 'category',
                        data: items
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        "name": "得票数",
                        "type": "bar",
                        "data": numberOfVoter
                    }
                ]
            };
            myChart.setOption(option);
        }
    });
</script>
</body>